/*
 * @Author: szx
 * @Date: 2022-05-24 13:08:20
 * @LastEditTime: 2022-05-24 13:15:28
 * @Description:
 * @FilePath: \leetcode\900-999\965\865.js
 */
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isUnivalTree = function (root) {
    const val = root.val;
    const dfs = (root) => {
        if (!root) return true;
        if (root.val !== val) return false;
        return dfs(root.left) && dfs(root.right);
    };
    return dfs(root);
};
